/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    //根据id,读取数据到页面
    var uid = getQueryString("uid");
    var sel = $.Params.create();
    sel.addParams("id",uid);
    sel.ajax(getIP()+"classRoom/getClass",function(data){
        if(data.success){
            var cTitle =data.result[0].cTitle;
			var cType = data.result[0].cType;
			var cAbstract = data.result[0].cAbstract;
            var imgUrl = data.result[0].pUrl;
			var urls = data.result[0].url;
            $("#cTitle").val(cTitle);
            $("#cType").val(cType);
            $("#cAbstract").val(cAbstract);
            $("#pUrl").attr("src","../img/"+imgUrl);
            $("#url").val(urls);
        }
    })

    //实时预览图片
    $("#loadImg").on("change", function(e){
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        for (var i = 0, len = files.length; i < len; ++i) {
            var file = files[i];

            if (url) {
                src = url.createObjectURL(file);
            } else {
                src = e.target.result;
            }

            $("#pUrl").attr('src', src);
        }
    });

    //修改信息
    $("#eid").val(uid);
    $("#updateInfo").on("click",function(){
        $("#updateForm").attr("action",getIP()+"classroom/updateImg");
        $("#updateForm").submit();
    })

    //取消修改信息
    $("#cancelUpdate").on("click",function() {
        history.back(-1);
    })
});
